package cn.ai.boot.config;

import java.util.concurrent.Semaphore;

// 辅助类实现自动释放
public class SemaphoreReleaser implements AutoCloseable {
    private final Semaphore semaphore;
    private boolean released = false;

    public SemaphoreReleaser(Semaphore semaphore) {
        this.semaphore = semaphore;
    }

    @Override
    public void close() {
        if (!released) {
            semaphore.release();
            released = true;
        }
    }
}